package com.xujl.mvcbind.adapter.provider;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.xujl.fastlib.base.BaseRvAdapter;
import com.xujl.fastlib.utils.ImgHelper;
import com.xujl.mvcbind.R;
import com.xujl.mvcbind.bean.FourMultiEntity;
import com.xujl.mvcbind.bean.ThreeMultiEntity;
import com.xujl.mvcbind.util.TimeLog;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

public class FourItemBinder extends AbsItemBinder<FourMultiEntity, BaseViewHolder> {
    private static final String TAG = "FourItemBinder";

    @Override
    public void convert (BaseViewHolder baseViewHolder, FourMultiEntity entity) {
        TimeLog.logStart(TAG);
        super.convert(baseViewHolder, entity);
        RecyclerView recyclerView = baseViewHolder.getView(R.id.rv);
        recyclerView.setLayoutManager(new GridLayoutManager(baseViewHolder.itemView.getContext(), 2));
        recyclerView.setAdapter(new BaseRvAdapter<ThreeMultiEntity>(R.layout.item_binder_three, entity.getList()) {

            @Override
            protected void convert (BaseViewHolder baseViewHolder, ThreeMultiEntity threeMultiEntity) {
                ImgHelper.loadImgNormal(baseViewHolder.itemView.getContext(), baseViewHolder.getView(R.id.iv), threeMultiEntity.getUrl());
                baseViewHolder.setText(R.id.tv_title, threeMultiEntity.getTitle())
                        .setText(R.id.tv_desc, threeMultiEntity.getDesc());
            }
        });
        TimeLog.logEnd(TAG);
    }

    @Override
    public BaseViewHolder onCreateViewHolder (ViewGroup viewGroup, int i) {
        final View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_binder_four, null);
        StaggeredGridLayoutManager.LayoutParams layoutParams = new StaggeredGridLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        layoutParams.setFullSpan(true);
        layoutParams.setMargins(10, 10, 10, 10);
        view.setLayoutParams(layoutParams);
        return new BaseViewHolder(view);
    }

}
